/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Track.Track;
import java.io.File;

/**
 *
 * @author Chris
 */
public class ModuleTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        Line Red = ExternFunc.TrackModel.Sys.LineList.get(0);
        Line Green = ExternFunc.TrackModel.Sys.LineList.get(1);
        
        System.out.println("\n\n\n\nTesting Red Line\n\n\n\n");
        for (int i = 0; i < Red.blockList.size(); i++){
            Block temp = Red.blockList.get(i);
            if (temp.hasCrossing){
                System.out.println("\n\nRed Line Block " + temp.id + " contains a Raillway Crossing.  Activating..");
                temp.Crossing.state = 1;
                if (temp.Crossing.state == 1){
                    System.out.println("\t\tCrossing active.  Deactivating...");
                    temp.Crossing.state = 0;
                }
                if (temp.Crossing.state == 0){
                    System.out.println("\t\tCrossing deactivated.");
                }
            }
            
            if (temp.hasStation){
                System.out.println("\n\nStation " + temp.blockStation.name + " located on Red Line at Block " + temp.id + ".");
            }
            
            System.out.println("Red Line Block " + temp.id + "    Underground: " + temp.isUnderground + "     Bidirectional: " + temp.bidirectional);
            
            ControllerInterface CI = temp.getControllerInterface();
            RailInterface RI = temp.getRailInterface();
            
            System.out.println("Contents of Controller Interface:    Max Speed Limit: " + CI.MaxSpeedLimit + ", CTC Requested Speed: " 
                    + CI.CTCRequestedSpeedLimit + ", Track Controller Set Speed Limit: " + CI.TrackControllerSetSpeedLimit + ", CTC Authority: " + CI.CTCAuthority + ", Track Controller Authority: " + CI.ControllerAuthority + ", Track Circuit Broken: " + CI.TrackCircuitValue + ".");
            System.out.println("Contents of Rail Interface:     Slope: " + RI.slope + "      Length: " + RI.length);
            
        }
        for (int i = 0; i < Red.switchList.size(); i++){
            Switch temp = Red.switchList.get(i);
            System.out.println("Red Line Switch " + temp.id + " Fixed Block: " + temp.fixed + " Connected Block: " + temp.connected + " Open Block : " + temp.open);
        } 
        System.out.println("\n\n\n\nTesting Green Line\n\n\n\n");
        
        for (int i = 0; i < Green.blockList.size(); i++){
            Block temp = Green.blockList.get(i);
            if (temp.hasCrossing){
                System.out.println("\n\nGreen Line Block " + temp.id + " contains a Raillway Crossing.  Activating..");
                temp.Crossing.state = 1;
                if (temp.Crossing.state == 1){
                    System.out.println("\t\tCrossing active.  Deactivating...");
                    temp.Crossing.state = 0;
                }
                if (temp.Crossing.state == 0){
                    System.out.println("\t\tCrossing deactivated.");
                }
            }
            
            if (temp.hasStation){
                System.out.println("\n\nStation " + temp.blockStation.name + " located on Green Line at Block " + temp.id + ".");
            }
            
            System.out.println("Green Line Block " + temp.id + "    Underground: " + temp.isUnderground + "     Bidirectional: " + temp.bidirectional);
            
            ControllerInterface CI = temp.getControllerInterface();
            RailInterface RI = temp.getRailInterface();
            
            System.out.println("\tContents of Controller Interface:    Max Speed Limit: " + CI.MaxSpeedLimit + ", CTC Requested Speed: " 
                    + CI.CTCRequestedSpeedLimit + ", Track Controller Set Speed Limit: " + CI.TrackControllerSetSpeedLimit + ", CTC Authority: " + CI.CTCAuthority + ", Track Controller Authority: " + CI.ControllerAuthority + ", Track Circuit Broken: " + CI.TrackCircuitValue + ".");
            System.out.println("\tContents of Rail Interface:     Slope: " + RI.slope + "      Length: " + RI.length);
        } 
        for (int i = 0; i < Green.switchList.size(); i++){
            Switch temp = Green.switchList.get(i);
            System.out.println("Green Line Switch " + temp.id + " Fixed Block: " + temp.fixed + " Connected Block: " + temp.connected + " Open Block : " + temp.open);
        } 
        
        
        System.out.println("Testing parts of module relating Trains");
        ExternFunc.addTrain(0, 0);
        ExternFunc.addTrain(1, 1);
        ExternFunc.addTrain(1, 2);
        ExternFunc.addTrain(0, 3);
        ExternFunc.addTrain(1, 4);
        if (ExternFunc.addTrain(0, 4) == -1)
            System.out.println("Train Not Added. ID 4 already exists.");//This should print
        ExternFunc.removeTrain(4);
        if (ExternFunc.addTrain(0, 4) == -1)
            System.out.println("Train Not Added. ID 4 already exists. BAD");//This should not print
        if (ExternFunc.addTrain(0, 5) == -1)
            System.out.println("Train Not Added. ID 5 already exists.");//This should not print
        
        System.out.println("Testing Head Transitions on Green Line tarting from Yard with intial configuration...");
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        ExternFunc.headBlockTransition(1);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        System.out.println("Testing adjusting a switch");
        System.out.println("Switch 5: Connected Block: " + Green.switchList.get(5).connected);
        ExternFunc.setSwitch(5, 1, 1);
        System.out.println("Switch 5: Connected Block: " + Green.switchList.get(5).connected);
        //ExternFunc.headBlockTransition(1);
        //System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(1).headBlockID);
        System.out.println("Error in switching Logic preventing succesful transitioning after adjusting switch on Green Line.");
        
        
        System.out.println("Testing Tail Transitions on Red Line Starting from Yard with intial configuration...");
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0); 
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0); 
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0); 
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0); 
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0); 
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        /*NullPointerException thrown if this line is ran
        ExternFunc.tailBlockTransition(0);
        System.out.println(ExternFunc.TrackModel.Sys.TrainList.get(0).tailBlockID);
        */
        
        System.out.println("Testing adjusting a switch");
        System.out.println("Switch 6: Connected Block: " + Red.switchList.get(6).connected);
        ExternFunc.setSwitch(6, 0, 1);
        System.out.println("Switch 6: Connected Block: " + Red.switchList.get(6).connected);
        //ExternFunc.tailBlockTransition(0);
        System.out.println("Error in switching Logic preventing succesful transitioning after adjusting switch on Red Line.");
        
    }
}
